package net.proef.sample.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Aspect
public class TracingAspect {

	private Logger logger = LoggerFactory.getLogger(TracingAspect.class);

	@Pointcut("execution(public * net.proef.sample.service.BookService.getAll*(..))")
	public void listAllItems() {
	}

	@Around("listAllItems()")
	public Object trace(ProceedingJoinPoint pjp) throws Throwable {
		Object result = null;

		try {
			logger.trace("Call '{}' args: {}", pjp.getSignature(),
					pjp.getArgs());
			result = pjp.proceed();
			logger.trace("'{}' returns {}", pjp.getSignature(), result);
		} catch (Throwable e) {
			throw e;
		}
		return result;
	}
}
